package com.up.blog.controller;


import com.alibaba.fastjson.JSON;
import com.up.blog.domain.Fansbean;
import com.up.blog.domain.PagebeanFan;
import com.up.blog.service.GetFansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;
@Controller
public class GetFansController  {
    @Autowired
    private GetFansService getFans;
    public static Integer page;
    public static Integer limit;
    @RequestMapping(value = "/getfans", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String findUserById(HttpServletRequest req, HttpServletResponse resp) {
        page = Integer.valueOf(req.getParameter("page"));
        limit = Integer.valueOf(req.getParameter("limit"));
        System.out.println("page=" + page + "limit=" + limit);
        PagebeanFan pagebeanFan=new PagebeanFan();
        String ret=null;
        try {
            List<Fansbean> fansBeanList=getFans.getFansbean(page,limit);
            System.out.println("fansBeanList"+fansBeanList);
            Long i=getFans.getCount();
            pagebeanFan.setData(fansBeanList);
            pagebeanFan.setCount(i);

            if(i>0){
                pagebeanFan.setCode(0);
            }else
                pagebeanFan.setCode(1);
            ret= JSON.toJSONString(pagebeanFan);

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ret;
    }

}
